﻿using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace MuHelper.Tests
{
    [TestClass]
    public class NumberWithMeasureToMeasure
    {
        [TestMethod]
        public void BaseMeasureToBaseMeasure()
        {
            var measure1 = new Measure("m");
            var measure2 = new Measure("s");
            var value = new NumberWithMeasure(12, measure1);
            var result1 = value.ToMeasure(measure2);
            Assert.AreEqual(result1, NumberWithMeasure.NaN);

            var result2 = value.ToMeasure(measure1);
            Assert.AreEqual(value, result2);
        }

        [TestMethod]
        public void BaseMeasureToComplexMeasure()
        {
            var measure1 = new Measure("m");
            var measure2 = new Measure("m_", 10, new Dictionary<string, decimal> {{"m", 1}});

            var value = new NumberWithMeasure(10, measure1);
            var result = value.ToMeasure(measure2);
            Assert.AreEqual(1, result.Value);
            Assert.AreEqual(measure2, result.Measure);
        }

        [TestMethod]
        public void ComplexMeasureToBaseMeasure()
        {
            var measure1 = new Measure("m_", 10, new Dictionary<string, decimal> { { "m", 1 } });
            var measure2 = new Measure("m");

            var value = new NumberWithMeasure(10, measure1);
            var result = value.ToMeasure(measure2);
            Assert.AreEqual(100, result.Value);
            Assert.AreEqual(measure2, result.Measure);
        }

        [TestMethod]
        public void ComplexMeasureToComplexMeasure()
        {
            var measure1 = new Measure("m3", 1, new Dictionary<string, decimal> {{"m", 3}});
            var measure2 = new Measure("L", (decimal)0.001, new Dictionary<string, decimal> {{"m", 3}});

            var value = new NumberWithMeasure(1, measure1);
            var result = value.ToMeasure(measure2);

            Assert.AreEqual(1000, result.Value);
            Assert.AreEqual(measure2, result.Measure);
        }
    }
}
